package eventplanner.rest;

import eventplanner.ejb.ServiceFacade;

import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/user")
public class UserService {

	@Inject
	private ServiceFacade serviceFacade;

	@POST
	@Path("/signin")
	@Produces(MediaType.APPLICATION_JSON)
	public Response login(@FormParam("username") String username, @FormParam("password") String password) {
		serviceFacade.login(username, password);
		return Response.ok(serviceFacade.isLoggedIn() ? "True" : "False").build();
	}

	@GET
	@Path("/isloggedin")
	@Produces(MediaType.APPLICATION_JSON)
	public Response isUserLoggedIn() {
		return Response.ok(serviceFacade.isLoggedIn() ? "True" : "False").build();
	}

	@POST
	@Path("/signout")
	@Produces(MediaType.APPLICATION_JSON)
	public Response logout() {
		serviceFacade.logout();
		return Response.ok().build();
	}

	@GET
	@Path("/authlevel")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAuthLevel() {
		return Response.ok(serviceFacade.getAuthLevel()).build();
	}

	@GET
	@Path("/info")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getInfo() {
		return Response.ok(serviceFacade.getInfo()).build();
	}
}
